package com.digital.herbarium.Util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class GetFieldValueUtil {

    public static String getValue(Object dto, String name) {
        try {
            Method m = (Method) dto.getClass().getMethod(("get" + name));

            String val = (String) m.invoke(dto);// 调用getter方法获取属性值
            return val;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
